package com.bite.friend.controller.user;
import com.bite.common.core.contants.HttpConstants;
import com.bite.common.core.controller.BaseController;
import com.bite.common.core.domain.R;
import com.bite.common.core.domain.vo.LoginUserVO;
import com.bite.friend.domain.user.dto.UserUpdateDTO;
import com.bite.friend.domain.user.dto.UserDTO;
import com.bite.friend.domain.user.vo.UserVO;
import com.bite.friend.service.user.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController extends BaseController {

    @Autowired
    private IUserService iUserService;

    /***
     * 获取验证码
     * 这里的返回值是是那么?为什么不是验证码,因为是发送手机上的,并不返回前端展示
     * @param userDTO
     * @return
     */
    @PostMapping("/sendCode")
    public R<Void> sendCode(@RequestBody  UserDTO userDTO){
        return toR(iUserService.sendCode(userDTO));
    }


    /**
     * 登录注册
     * @param userDTO
     * @return
     */
    //code
    @PostMapping("/code/login")
    public R<String> codeLogin(@RequestBody UserDTO userDTO){
        return R.ok(iUserService.codeLogin(userDTO.getPhone(),userDTO.getCode()));
    }

    /**
     * 退出登录
     * @param token
     * @return
     */
    @DeleteMapping("/logout")
    public R<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return toR(iUserService.logout(token));

    }


    @GetMapping("/info")
    public R<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return iUserService.info(token);
    }

    @GetMapping("/detail")
    public R<UserVO> detail(){
        return R.ok(iUserService.detail());
    }



    @PutMapping("/edit")
    public R<Void> edit(@RequestBody UserUpdateDTO userUpdateDTO){
        return toR(iUserService.edit(userUpdateDTO));
    }


    /**
     * 获取用户头像唯一标识   --更新
     */
    @PutMapping("/head-image/update")
    public R<Void> updateHeadImage(@RequestBody UserUpdateDTO userUpdateDTO){
        return toR(iUserService.updateHeadImage(userUpdateDTO.getHeadImage()));
    }
}
